package com.bj58.ecdata.dashboard.constant;

import java.util.Calendar;
import java.util.List;


import com.alibaba.fastjson.JSONArray;
import com.bj58.ecdata.dashboard.utils.DDateUtils;
import com.google.common.base.Joiner;

public class IncomeCityConst {

	public static final JSONArray ZX_CityList = JSONArray.parseArray("['全国','直销城市','渠道城市','北京','上海', '天津', '广州', '深圳', '成都', '重庆', '石家庄', '济南', '青岛', '南京', '杭州', '苏州', '无锡', '合肥', '武汉', '郑州', '长沙', '福州', '厦门', '南宁', '哈尔滨', '长春', '太原', '大连', '沈阳', '东莞']");
	
	/**
	 * 城市三个产品线查询列，查询条件
	 * @param dateGroup
	 * @return
	 */
	public static String getCityProCol(String dateGroup){
		return dateGroup+",jingzhun_cash, jingzhun_user, zhiding_cash, zhiding_user, zhineng_cash, zhineng_user";
	}
	
	private static final String PATTEN_CityPro = "city_name='%s' AND business_name='%s' AND stat_type='%s' GROUP BY %s";
	
	public static String getCityProCon(String dateGroup, String stat_type, String businessName, String cityName){
		return String.format(PATTEN_CityPro, cityName, businessName, stat_type, dateGroup);
	}
	
	/**
	 * 27个直销城市三个产品线 表格数据查询条件
	 * @param dateGroup
	 * @return
	 */
	private static final String CityPro_Table = "%s='%s' AND business_name='%s' AND stat_type='%s' GROUP BY city_name";
	
	public static String getCityProTableCon(String dateGroup, String stat_type, String businessName, String dateVal){
		return String.format(CityPro_Table, dateGroup,dateVal, businessName, stat_type);
	}
	
	private static final String CON_CityCmp = "city_name in('%s','%s') AND business_name='%s' AND stat_type='%s' GROUP BY city_name,%s";
	private static final String COL_CityCmp = "%s,city_name,%s_cash, %s_user";
	/**
	 * 城市对比查询列，查询条件
	 * @param dateGroup
	 * @return
	 */
	public static String getCityCmpCol(String dateGroup, String proType){
		return String.format(COL_CityCmp, dateGroup,proType,proType);
	}
	
	public static String getCityCmpCon(String dateGroup, String stat_type, String businessName, String city1,String city2){
		return String.format(CON_CityCmp, city1,city2, businessName, stat_type, dateGroup);
	}

	
	private static final String CON_CityConsume = "stat_type='%s' AND city_name in('%s') AND business_name='%s' GROUP BY city_name,%s";
	private static final String COL_CityConsume = "%s,city_name,%s, %s";
	/*
	 * 消耗周期
	 */
	public static String getCityConsumeCol(String dateGroup,String index1, String index2) {
		return String.format(COL_CityConsume,dateGroup,index1, index2);
	}

	public static String getCityConsumeCon(String businessName,String dateGroup,String statType, List<String> cityArr) {
		String cityString  = Joiner.on("','").join(cityArr); //去掉 [ ]
		return String.format(CON_CityConsume,statType,cityString,businessName,dateGroup);
	}

	private static final String CON_CityConsumeTable = "business_name='%s' and stat_type='%s' and %s='%s' GROUP BY city_name";

	/*
	 * 消耗周期表格数据
	 */
	public static String getCityConsumeTableCon(String businessName,String dateGroup,String statType,String dateVal) {
		return String.format(CON_CityConsumeTable,businessName,statType,dateGroup, dateVal);
	}	
	
	private static final String CON_CityRadar = "city_name in('%s') AND business_name='%s' AND stat_type='%s' AND is_vip='%s' GROUP BY city_name,stat_date";
	
	public static String getCityRadarCon( String stat_type,String date, String businessName, List<String> cityArr,String is_vip) {
		StringBuilder sBuilder = new StringBuilder();
		String cityString = Joiner.on("','").join(cityArr); //去掉 [ ]
		
		sBuilder.append("stat_date>='");
		String beginDate = null;
		if("day".equals(stat_type)){
			beginDate = DDateUtils.varDate(date, "yyyy-MM-dd", Calendar.DATE, -11); //12个点
		}else if("week".equals(stat_type)){
			beginDate = DDateUtils.varDate(date, "yyyy-MM-dd", Calendar.DATE, -11*7);
		}
		sBuilder.append(beginDate +"' and  stat_date<='"+date+"' and ");
		return sBuilder + String.format(CON_CityRadar,cityString,businessName,stat_type,is_vip);

	}

	private static final String CON_CityRadar_Table = "stat_date='%s' AND business_name='%s' AND stat_type='%s' AND is_vip='%s' GROUP BY city_name";

	public static String getCityRadarTableCon(String stat_type, String dateVal, String businessName, String is_vip) {
		return String.format(CON_CityRadar_Table, dateVal, businessName, stat_type,is_vip);
	}
	
}
